import 'package:flutter/material.dart';
import 'package:flutter_novel/detail/data/model/detail_model_entity.dart';
import 'package:flutter_novel/detail/router/home_router.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class DesWidget extends StatelessWidget {
  final DetailModelData? model;

  const DesWidget({super.key, this.model});

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [_buildTagsSection(), _buildDescriptionSection(), _buildCommentsSection(context)],
      ),
    );
  }

  Widget _buildTagsSection() {
    if (model == null) return SizedBox();
    return SingleChildScrollView(
      scrollDirection: Axis.horizontal,
      child: Padding(
        padding: EdgeInsets.only(left: 15.w, top: 10.h, bottom: 10.h),
        child: Row(
          children: [_buildTag(model!.style.name), ...model!.tag.map((tag) => _buildTag(tag.name))],
        ),
      ),
    );
  }

  Widget _buildTag(String text) {
    return Padding(
      padding: EdgeInsets.only(right: 8.w),
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 5.h),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(4.r),
          color: const Color(0xFFF6F9FF),
        ),
        child: Text(
          text,
          style: TextStyle(fontSize: 12.sp, color: const Color(0xFF666666)),
        ),
      ),
    );
  }

  Widget _buildDescriptionSection() {
    return Padding(
      padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 15.h),
      child: Text(
        model?.evaluate ?? '',
        style: TextStyle(color: const Color(0xFF666666), fontSize: 12.sp, height: 2.h),
      ),
    );
  }

  Widget _buildCommentsSection(BuildContext context) {
    return InkWell(
      onTap: (){
        HomeDetailNavigator.toCommitsPage(context);
      },
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 15.w, vertical: 15.h),
        padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 10.h),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(4.r),
          border: Border.all(width: 1.w, color: const Color(0xFFF3F5FA)),
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              '小说讨论区',
              style: TextStyle(
                color: const Color(0xFF000000),
                fontSize: 14.sp,
                fontWeight: FontWeight.w500,
              ),
            ),
            const Spacer(),
            Text(
              '2202条评论等你来 ',
              style: TextStyle(color: const Color(0xFF666666), fontSize: 10.sp),
            ),
            Image.asset(
              'assets/images/ic_arrows.png',
              width: 15.w,
              height: 20.h,
              color: const Color(0xFF586C94),
            ),
          ],
        ),
      ),
    );
  }
}
